/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package entidades;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author dvasquez
 */
@Entity
@Table(name = "formulario")
@NamedQueries({
    @NamedQuery(name = "Formulario.findAll", query = "SELECT f FROM Formulario f"), @NamedQuery(name = "Formulario.findByNroOT", query = "SELECT f FROM Formulario f WHERE f.nroOT = :nroOT"), @NamedQuery(name = "Formulario.findById", query = "SELECT f FROM Formulario f WHERE f.id = :id"), @NamedQuery(name = "Formulario.findByCodigoEnsayo", query = "SELECT f FROM Formulario f WHERE f.codigoEnsayo = :codigoEnsayo"), @NamedQuery(name = "Formulario.findByRut", query = "SELECT f FROM Formulario f WHERE f.rut = :rut"),
    @NamedQuery(name = "Formulario.findById", query = "SELECT f FROM Formulario f WHERE f.id = :id"),
    @NamedQuery(name = "Formulario.findByFecha", query = "SELECT f FROM Formulario f WHERE f.fecha = :fecha"),
    @NamedQuery(name = "Formulario.findByEnsayo", query = "Select f FROM Formulario f JOIN f.codigoEnsayo o WHERE o.codigoEnsayo = :ensayo"),
    @NamedQuery(name = "Formulario.findByArea", query = "Select f FROM Formulario f JOIN f.codigoEnsayo o WHERE o.area = :area"),
    @NamedQuery(name = "Formulario.findByNroOT", query = "Select f FROM Formulario f JOIN f.nroOT o WHERE o.nroOT = :nroOT"),
    @NamedQuery(name = "Formulario.findByRangoAndUser", query = "Select f FROM Formulario f where f.fecha between :fechainicio and :fechatermino and f.rut.rut = :rut"),
    @NamedQuery(name = "Formulario.findByRangoUserArea", query = "Select f From Formulario f where f.fecha between :fechainicio and :fechatermino and f.rut.rut = :rut and f.codigoEnsayo = :area")
})
public class Formulario implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID")
    private Integer id;
    @Column(name="id_externo")
    private Integer id_externo;
    @Column(name="estado")
    private String estado;
    @Column(name = "fecha")
    @Temporal(TemporalType.DATE)
    private Date fecha;
    @JoinColumn(name = "rut", referencedColumnName = "rut")
    @ManyToOne
    private Usuario rut;
    @JoinColumn(name="nroOT", referencedColumnName = "nroOT")
    @ManyToOne
    private OrdenDeTrabajo nroOT;
    @JoinColumn(name = "codigoEnsayo", referencedColumnName = "codigoEnsayo")
    @ManyToOne
    private Ensayo codigoEnsayo;


    public Formulario() {
    }

    public Formulario(Integer id) {
        this.id = id;
    }

    public OrdenDeTrabajo getNroOT() {
        return nroOT;
    }

    public void setNroOT(OrdenDeTrabajo nroOT) {
        this.nroOT = nroOT;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getId_externo() {
        return id_externo;
    }

    public void setId_externo(Integer id_externo) {
        this.id_externo = id_externo;
    }

    public Date getFecha() {
        return fecha;
    }

    public void setFecha(Date fecha) {
        this.fecha = fecha;
    }

    public Ensayo getCodigoEnsayo() {
        return codigoEnsayo;
    }

    public void setCodigoEnsayo(Ensayo codigoEnsayo) {
        this.codigoEnsayo = codigoEnsayo;
    }

    public Usuario getRut() {
        return rut;
    }

    public void setRut(Usuario rut) {
        this.rut = rut;
    }

    public String getEstado() {
        return estado;
    }

    public void setEstado(String estado) {
        this.estado = estado;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Formulario)) {
            return false;
        }
        Formulario other = (Formulario) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entidades.Formulario[id=" + id + "]";
    }

}
